#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

class Date
{
public:
	friend ostream& operator<<(ostream& os, Date& d);

	Date(int _year, int _month, int _day)
		: _year(_year)
		, _month(_month)
		, _day(_day)
	{}

	int getDay(int year, int month)
	{
		static int arr[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
		if (month == 2 && ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)))
			return 29;
		else
			return arr[month];
	}

	Date& operator+(int x)
	{
		_day += x;
		while (_day > getDay(_year, _month))
		{
			_day -= getDay(_year, _month);
			_month++;
			if (_month == 13)
			{
				_month = 1;
				_year++;
			}
		}
		return *this;
	}

private:
	int _year;
	int _month;
	int _day;
};

ostream& operator<<(ostream& os, Date& d)
{
	if(d._month >= 10 && d._day >= 10)
		os << d._year << "-" << d._month << "-" << d._day;
	else if (d._month < 10 && d._day < 10)
		os << d._year << "-0" << d._month << "-0" << d._day;
	else if (d._month >= 10 && d._day < 10)
		os << d._year << "-" << d._month << "-0" << d._day;
	else if (d._month < 10 && d._day >= 10)
		os << d._year << "-0" << d._month << "-" << d._day;
	return os;
}

int main()
{
	int n;
	cin >> n;
	for (int i = n; n > 0; n--)
	{
		int year, month, day, add_day;
		cin >> year >> month >> day >> add_day;
		Date d(year, month, day);
		cout << d + add_day << endl;
	}

	return 0;
}
